[tests] Replace legacy [TestFixtureSetUp]/[TestFixtureTearDown] with [OneTimeSetUp]/[OneTimeTearDown]#1437
Merged
Conversation
…[OneTimeSetUp]/[OneTimeTearDown] The legacy `[TestFixtureSetUp]` and `[TestFixtureTearDown]` attributes were removed in NUnit 3 in favor of `[OneTimeSetUp]` and `[OneTimeTearDown]`. They have been kept around in NUnitLite for back-compat, which is why the on-device Android test path used them under `#if __ANDROID__`. NUnitLite also supports the modern `OneTime*` names, so the conditional is no longer needed. Replacing the conditional with the unconditional modern attribute unblocks dotnet/android#11224, which migrates Mono.Android device tests from NUnitLite to stock NUnit 3.13.3 + MTP via `dotnet test`. Stock NUnit 3.13.3's `netstandard2.0` assembly does not contain the legacy attribute names, so consuming this code there currently requires a small compatibility shim (NUnitCompatibility.cs). After this change that shim can be deleted. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates Java.Interop test fixtures to use NUnit 3’s modern one-time fixture lifecycle attributes consistently, removing Android-specific conditional compilation that depended on legacy NUnit2 attribute names. This aligns the test code with stock NUnit 3.x (netstandard2.0) and helps unblock downstream migration work.
Changes:
- Replaced
#if __ANDROID__blocks using[TestFixtureSetUp]/[TestFixtureTearDown]with unconditional[OneTimeSetUp]/[OneTimeTearDown]. - Applied the change across the three affected test fixtures/contracts to keep behavior consistent across platforms.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/Java.Interop-Tests/Java.Interop/TestTypeTests.cs | Removes Android-only legacy NUnit2 attribute usage; uses OneTime* attributes unconditionally. |
| tests/Java.Interop-Tests/Java.Interop/JavaObjectArrayTest.cs | Removes Android-only legacy NUnit2 attribute usage for global-ref counting setup/teardown. |
| tests/Java.Interop-Tests/Java.Interop/JavaArrayContract.cs | Removes Android-only legacy NUnit2 attribute usage in the shared array contract base class. |
simonrozsival
approved these changes
Jun 2, 2026
jonathanpeppers
added a commit
to dotnet/android
that referenced
this pull request
Jun 2, 2026
dotnet/java-interop#1437 replaces the legacy [TestFixtureSetUp] / [TestFixtureTearDown] attributes with the modern [OneTimeSetUp] / [OneTimeTearDown] names that stock NUnit 3 ships out of the box, so the local NUnitCompatibility.cs shim is no longer needed. Submodule bump: e38211334 -> b982a1a3 (dotnet/java-interop): b982a1a [tests] Replace [TestFixtureSetUp]/[TestFixtureTearDown] with [OneTimeSetUp]/[OneTimeTearDown] (#1437) e68fa0a Bump to dotnet/android-tools@3c95718 (#1436) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The legacy
[TestFixtureSetUp]and[TestFixtureTearDown]attributes were removed in NUnit 3 in favor of[OneTimeSetUp]and[OneTimeTearDown]. They have been kept around in NUnitLite for back-compat, which is why the on-device Android test path used them under#if __ANDROID__. NUnitLite also supports the modernOneTime*names, so the conditional is no longer needed.This replaces the
#if __ANDROID__/#else/#endifblocks with the unconditional modern attribute in the three affected files:tests/Java.Interop-Tests/Java.Interop/TestTypeTests.cstests/Java.Interop-Tests/Java.Interop/JavaObjectArrayTest.cstests/Java.Interop-Tests/Java.Interop/JavaArrayContract.csWhy
This unblocks dotnet/android#11224, which migrates
Mono.Androiddevice tests from NUnitLite to stock NUnit 3.13.3 + MTP viadotnet test. Stock NUnit 3.13.3'snetstandard2.0assembly does not contain the legacy attribute names, so consuming Java.Interop's test code there currently requires a small compatibility shim (NUnitCompatibility.cs). After this change that shim can be deleted.Verification
dotnet build tests/Java.Interop-Tests/Java.Interop-Tests.csprojsucceeds.